package com.student.education.controller;

import com.student.education.common.CommonResult;
import com.student.education.entity.Role;
import com.student.education.service.RoleService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

@RestController
@RequestMapping("role")
public class RoleController {

    @Resource
    private RoleService roleService;
    //查询
    @PostMapping("queryAll")
    public CommonResult<List<Role>> queryAll(@RequestBody Role vo){
        List<Role> roleList = roleService.queryAll(vo);
        return CommonResult.success(roleList);
    }

    //修改
    @PostMapping("update")
    public CommonResult<String> update(@RequestBody Role vo) {
        int i = roleService.update(vo);
        if (Objects.equals(i, 1)) {
            return CommonResult.success("修改成功");
        }
        return CommonResult.error("修改失败");
    }

    //新增
    @PostMapping("add")
    public CommonResult<String> add(@RequestBody Role vo){
        int i = roleService.add(vo);

        if (Objects.equals(i, 1)) {
            return CommonResult.success("添加成功");
        }
        return CommonResult.error("添加失败");

    }

    //删除
    @GetMapping("delete")
    public CommonResult<String> delete(@RequestParam Integer id) {
        int i = roleService.delete(id);
        if (Objects.equals(i, 1)) {
            return CommonResult.success("删除成功");
        }
        return CommonResult.error("删除失败");
    }


}
